<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AlterUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('mobile')->nullable(true)->comment('电话');
            $table->string('remarks')->nullable(true)->comment('备注');
            $table->dropUnique('users_email_unique');
            $table->string('email')->nullable(true)->change();
            $table->string('name')->unique()->change();
        });
        Schema::create('user_managements', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('user_id')->nullable(true)->comment('用户id'); 
            $table->string('name');
            $table->morphs('manage');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('name')->nullable(false)->change();
            $table->string('email')->unique()->change();
            $table->dropUnique('users_name_unique');
            $table->dropColumn('mobile');
            $table->dropColumn('remarks');
        });
        Schema::dropIfExists('user_managements');
    }
}
